package com.service.impl;

import com.two.BaseMapper;
import com.service.BaseService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.dao.DataAccessException;

import java.io.Serializable;
import java.util.List;

/**
 * Created by Likuo on 2018/8/24.
 *
 * @Description:
 */

public class BaseServiceImpl<T,PK extends Serializable> implements BaseService<T,PK> {
    @Autowired
    private BaseMapper<T> mapper;

    @Override
    public T getById(PK id) throws DataAccessException {
        return (T)mapper.selectByPrimaryKey(id);
    }

    @Override
    public int save(T entity) throws DataAccessException {
        return mapper.insert(entity);
    }

    @Override
    public int removeById(PK id) throws DataAccessException {
        return mapper.deleteByPrimaryKey(id);
    }

    @Override
    public int update(T entity) throws DataAccessException {
        return mapper.updateByPrimaryKeySelective(entity);
    }

    @Override
    public int insertList(List<T> list) throws DataAccessException {
        return mapper.insertList(list);
    }

    @Override
    public List<T> getAllData() throws DataAccessException {
        return mapper.selectAll();
    }
}
